import 'package:flutter/material.dart';

//ListView列表组件
void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(home: MyTabs());
  }
}

// class HomePage extends StatelessWidget {
//   const HomePage({super.key});

//   @override
//   Widget build(BuildContext context) {
//     return Scaffold(
//       appBar: AppBar(
//         title: Text('bottomNavigationBar底部导航组件'),
//         backgroundColor: const Color.fromARGB(255, 2, 209, 154),
//       ),
//       body: Text('bottomNavigationBar底部导航组件'),
//       bottomNavigationBar: BottomNavigationBar(
//         currentIndex: 1,//默认选中第几个
//         onTap: (index) {
//           print(index);
//         },//选中变化回调函数
//         items: [
//           BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
//           BottomNavigationBarItem(icon: Icon(Icons.category), label: '分类'),
//           BottomNavigationBarItem(icon: Icon(Icons.settings), label: '设置'),
//         ],
//       ),
//     );
//   }
// }

class MyTabs extends StatefulWidget {
  const MyTabs({super.key});

  @override
  State<MyTabs> createState() => _MyWidgetState();
}

class _MyWidgetState extends State<MyTabs> {
  int _currentIndex = 0;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('bottomNavigationBar底部导航组件'),
        backgroundColor: const Color.fromARGB(255, 2, 209, 154),
      ),
      body: Text('bottomNavigationBar底部导航组件'),
      bottomNavigationBar: BottomNavigationBar(
        currentIndex: _currentIndex, //默认选中第几个
        onTap: (index) {
          setState(() {
            _currentIndex = index;
          });
        }, //选中变化回调函数
        items: [
          BottomNavigationBarItem(icon: Icon(Icons.home), label: '首页'),
          BottomNavigationBarItem(icon: Icon(Icons.category), label: '分类'),
          BottomNavigationBarItem(icon: Icon(Icons.settings), label: '设置'),
        ],
      ),
    );
  }
}
